package com.zzptc.myapp1202;

import android.content.Context;
import android.graphics.Color;
import android.net.Uri;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.github.mikephil.charting.charts.Chart;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;

import java.util.ArrayList;


public class FristFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_frist, container, false);
        LineChart lineChart = view.findViewById(R.id.line_Chart);
        ArrayList<Entry> list = new ArrayList<>();

        list.add(new Entry(1, 2));
        list.add(new Entry(2, 3));
        list.add(new Entry(3, 8));
        list.add(new Entry(4, 0));
        list.add(new Entry(5, 1));

        ArrayList<Entry> list1 = new ArrayList<>();


        list1.add(new Entry(1, 8));
        list1.add(new Entry(2, 6));
        list1.add(new Entry(3, 7));
        list1.add(new Entry(4, 5));
        list1.add(new Entry(5, 3));

        LineDataSet lineDataSet = new LineDataSet(list, "");//设置参数 2个
        LineDataSet lineDataSet1 = new LineDataSet(list1, "");//设置参数 2个 这是第二个


        lineDataSet.setCircleColor(Color.BLUE);//设置标记点颜色
        lineDataSet.setColor(Color.BLACK);//设置线的颜色

        lineDataSet1.setCircleColor(Color.BLACK);//设置标记点颜色
        lineDataSet1.setColor(Color.RED);//设置线的颜色



        lineDataSet.setLineWidth(2f);//设置线的宽度
        ArrayList<ILineDataSet> iLineDataSets = new ArrayList<>();//双线并合
        iLineDataSets.add(lineDataSet);
        iLineDataSets.add(lineDataSet1);

        LineData lineData = new LineData(lineDataSet);
        lineData.addDataSet(lineDataSet);
        lineData.addDataSet(lineDataSet1);
        lineChart.setData(lineData);

        XAxis xAxis = lineChart.getXAxis();//设置X轴
        xAxis.setPosition(XAxis.XAxisPosition.BOTTOM);//设置X轴
        xAxis.setAxisMaximum(5);//设置最大值
        xAxis.setAxisMinimum(1);//设置最小值
        xAxis.setLabelCount(5);//设置设置标签计数

        return view;
    }
}